﻿
@using BBICMS.Model.Works
@model BBICMS.Application.InputModels.Works.WorkIM
@{
    ViewBag.Title = string.Format(Titles.Add,EntityNames.Work);
    ViewBag.PageTitle = ViewBag.Title + "_内容";
    
}

@section Header{
    <script src="~/plugins/ckeditor/ckeditor.js"></script>
    <script src="~/plugins/ckfinder/ckfinder.js"></script>
}





    <div class="panel panel-default">
    <header class="panel-heading">
        <span class="glyphicon glyphicon-edit"></span> @ViewBag.Title

    </header>

    <section class="panel-body">

        @using (Ajax.BeginForm("AddWork", "Work", new AjaxOptions()
        {

            HttpMethod = "POST",
            OnBegin = "onBeginSave",
            OnComplete = "onCompleteSave",
            OnSuccess = "updateSuccess"

        }, new { @class = "form-horizontal", role = "form" }))
        {

            @Html.AntiForgeryToken()
            @Html.ValidationSummary(true)

            <div class="form-group">
                @Html.LabelFor(model => model.Title, new { @class = "col-md-2 control-label" })
                <div class="col-md-5">
                    @Html.TextBoxFor(model => model.Title, new { @class = "form-control", placeholder = ModelMetadata.FromLambdaExpression(x => x.Title, ViewData).Watermark })
                    @Html.ValidationMessageFor(model => model.Title)
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.ClientId, new { @class = "col-md-2 control-label" })
                <div class="col-md-5">
                    @Html.DropDownListFor(model => model.ClientId, (SelectList)ViewBag.Clients, "--所属客户--", new { @class = "form-control", placeholder = ModelMetadata.FromLambdaExpression(x => x.ClientId, ViewData).Watermark })
                    @Html.ValidationMessageFor(model => model.ClientId)
                </div>

            </div>

        

            <div class="form-group">
                @Html.LabelFor(model => model.SolutionId, new {@class = "col-md-2 control-label"})
                <div class="col-md-5">
                    @Html.DropDownListFor(model => model.SolutionId, (SelectList) ViewBag.Solutions,"--所属解决方案--", new {@class = "form-control", placeholder = ModelMetadata.FromLambdaExpression(x => x.SolutionId, ViewData).Watermark})
                    @Html.ValidationMessageFor(model => model.SolutionId)
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.FinishYear, new { @class = "col-md-2 control-label" })
                <div class="col-md-5">
                    @Html.TextBoxFor(model => model.FinishYear, new { @class = "form-control", placeholder = ModelMetadata.FromLambdaExpression(x => x.FinishYear, ViewData).Watermark })
                    @Html.ValidationMessageFor(model => model.FinishYear)
                </div>
            </div>


                <div class="form-group">
                    @Html.LabelFor(model => model.WorkTypesIds, new { @class = "col-md-2 control-label" })
                    <div class="col-md-10">
                        @foreach (var t in (List<WorkType>)ViewBag.Types)
                        {
                            <label class="checkbox-inline">
                                <input type="checkbox" name="WorkTypesIds" value="@t.Id"> @t.Title
                            </label>
                        }
                      
                        @Html.ValidationMessageFor(model => model.WorkTypesIds)
                    </div>

                </div>

                <div class="form-group">
                    @Html.LabelFor(model => model.Thumbnail, new { @class = "col-md-2 control-label" })
                    <div class="col-md-5">
                        <div class="input-group">
                            @Html.TextBoxFor(model => model.Thumbnail, new { @class = "form-control", placeholder = "图片大小为：215X215像素" })
                            <span class="input-group-btn">
                                <button class="btn btn-default" id="btnThumbnail" type="button">浏览…</button>
                            </span>
                        </div><!-- /input-group -->
                        <span class="help-block"></span>
                 
                        @Html.ValidationMessageFor(model => model.Thumbnail)
                    </div>
                </div>

                <div class="form-group">
                    @Html.LabelFor(model => model.ImageUrl, new { @class = "col-md-2 control-label" })
                    <div class="col-md-5">
                        <div class="input-group">
                            @Html.TextBoxFor(model => model.ImageUrl, new { @class = "form-control", placeholder = ModelMetadata.FromLambdaExpression(x => x.ImageUrl, ViewData).Watermark })
                            <span class="input-group-btn">
                                <button class="btn btn-default" id="btnImageUrl" type="button">浏览…</button>
                            </span>
                        </div><!-- /input-group -->
                    </div>
                    <div class="col-md-5">
                        @Html.ValidationMessageFor(model => model.ImageUrl)
                    </div>
                </div>

                <div class="form-group">
                    @Html.LabelFor(model => model.Demourl, new { @class = "col-md-2 control-label" })
                    <div class="col-md-5">
                        @Html.TextBoxFor(model => model.Demourl, new { @class = "form-control" })
                        @Html.ValidationMessageFor(model => model.Demourl)
                    </div>

                </div>

                <div class="form-group">
                    @Html.LabelFor(model => model.Body, new { @class = "col-md-2 control-label" })
                    <div class="col-md-10">
                        @Html.TextAreaFor(model => model.Body, new { @class = "form-control", placeholder = ModelMetadata.FromLambdaExpression(x => x.Body, ViewData).Watermark })
                        @Html.ValidationMessageFor(model => model.Body)
                    </div>

                </div>

                <div class="form-group">
                    @Html.LabelFor(model => model.Abstract, new { @class = "col-md-2 control-label" })
                    <div class="col-md-5">
                        @Html.TextAreaFor(model => model.Abstract, new { @class = "form-control", placeholder = ModelMetadata.FromLambdaExpression(x => x.Abstract, ViewData).Watermark })
                    </div>
                    <div class="col-md-5">
                        @Html.ValidationMessageFor(model => model.Abstract)
                    </div>
                </div>


                <div class="form-group">
                    @Html.LabelFor(model => model.KeyWords, new { @class = "col-md-2 control-label" })
                    <div class="col-md-5">
                        @Html.TextBoxFor(model => model.KeyWords, new { @class = "form-control", placeholder = ModelMetadata.FromLambdaExpression(x => x.KeyWords, ViewData).Watermark })
                    </div>
                    <div class="col-md-5">
                        @Html.ValidationMessageFor(model => model.KeyWords)
                    </div>
                </div>



                <div class="form-group">
                    <div class="col-md-10 col-md-offset-2">
                        <div class="checkbox">
                            <label>
                                @Html.CheckBoxFor(model => model.Recommend)  @Html.DisplayNameFor(model => model.Recommend)  @Html.ValidationMessageFor(model => model.Recommend)
                            </label>
                        </div>
                    </div>
                </div>


                <div class="form-group">

                    <div class="col-md-10 col-md-offset-2">
                        <div class="checkbox">
                            <label>
                                @Html.CheckBoxFor(model => model.Active)  @Html.DisplayNameFor(model => model.Active)  @Html.ValidationMessageFor(model => model.Active)
                            </label>
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-offset-2 col-md-10">
                        <button type="submit" class="btn btn-primary" id="btnSave"><i class="fa fa-save fa-fw"></i>  @Buttons.Add </button> 
                        <a href="@Url.Action("Index")" class="btn btn-default"><span class="glyphicon glyphicon-arrow-left"></span> 返回</a>
                    </div>
                </div>

        }

    </section>


</div>









@section Footer {

    @Scripts.Render("~/bundles/jqueryvalWithBootstrap")


    <script>
        var editor = CKEDITOR.replace("Body", {
            filebrowserImageBrowseUrl: '/plugins/ckfinder/ckfinder.html?type=Images',
            filebrowserUploadUrl: '/plugins/ckfinder/core/connector/aspx/connector.aspx?command=QuickUpload&type=Files',
            filebrowserImageUploadUrl: '@Url.Content("~/Content/Uploads")'
        }
            );
        CKFinder.setupCKEditor(editor, '@Url.Content("~/plugins/ckfinder/")');


        function SetThumbnail(fileUrl) {
            $('#Thumbnail').val(fileUrl);
        }

        function SetImageUrl(fileUrl) {
            $('#ImageUrl').val(fileUrl);
        }


        function onBeginSave() {
            $("#btnSave i").removeClass("fa-save").addClass("fa-spinner fa-spin");

        }
        function onCompleteSave() {
            $("#btnSave i").removeClass("fa-spinner fa-spin").addClass("fa-save");
        }

        function updateSuccess(data) {

             var title = '@ViewBag.Title';
        Common.ShowBox(data.Status, data.Message, title);


        }



        $(function () {
            $("#btnThumbnail").on("click", function () {
                var finder = new CKFinder();
                //  finder.basePath = '/plugins/ckfinder/';
                finder.selectActionFunction = SetThumbnail;
                finder.popup();
            });

            $("#btnImageUrl").on("click", function () {
                var finder = new CKFinder();
                finder.selectActionFunction = SetImageUrl;
                finder.popup();
            });

            //当前菜单
            $('.mainmenu>li').eq(1).addClass('nav-open').find('.submenu li:nth-of-type(1)').children('a').addClass('active');

            //转换boostrap 验证
            $('span.field-validation-valid, span.field-validation-error').each(function () {
                $(this).addClass('help-block');
            });

            var $form = $('form');
            var $validate = $form.validate();
            var errorClass = "has-error";
            //var successClass = "has-success";
            $validate.settings.errorClass = errorClass;
            var previousEPMethod = $validate.settings.errorPlacement;
            $validate.settings.errorPlacement = $.proxy(function (error, inputElement) {
                if (previousEPMethod) {
                    previousEPMethod(error, inputElement);
                }
                inputElement.parent().addClass(errorClass)
            }, $form[0]);

            var previousSuccessMethod = $validate.settings.success;
            $validate.settings.success = $.proxy(function (error) {
                //we first need to remove the class, cause the unobtrusive success method removes the node altogether
                error.parent().parent().removeClass(errorClass)
                if (previousSuccessMethod) {
                    previousSuccessMethod(error);
                }
            });


        });
    </script>
}